<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

use Illuminate\Support\Facades\DB;
//haha
//主页
Route::get('/', 'IndexController@index');

//搜索
Route::get('search/{key?}','IndexController@searchGet');
Route::post('search','IndexController@searchPost');

//发起投票页面
Route::get('vote/{tid}','IndexController@vote');
//投票
Route::post('vote','IndexController@votePost');
//预览结果
Route::get('result/{tid}','IndexController@showResult');


//预览页面
Route::get('prev','UserController@prev');
//更改投票
Route::get('upVote/{tid}','UserController@up');
Route::post('upVote/{tid}','UserController@upPost');
//删除投票
Route::get('delVote/{tid}','UserController@delVote');
//投票预览
Route::get('prevVote','UserController@prevVote');
//帖子预览
Route::get('prevPost','UserController@prevPost');
//评论预览
Route::get('prevComm','UserController@prevComm');


//搜索路由
Route::post('sea','UserController@sea');
//搜索出错
Route::get('seaErr','UserController@seaErr');



//添加页面
Route::get('add','UserController@add');

//未完页面
Route::get('not','UserController@not');


Route::get('createTextVote','CreateController@createTextVote');
Route::get('createImgVote','CreateController@createImgVote');
Route::post('createTextVote','CreateController@addTextVote');
Route::post('createImgVote','CreateController@addImgVote');

// 用户登录，注册
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

Route::get('test', function() {
    /*
    select a.tid, title, count(*) as person
    from (select tid, ip from votes group by tid, ip) as a inner join topics
    on a.tid = topics.tid
    group by tid
    order by person desc
    */
//    $rs = DB::table('votes')
//        ->select(DB::raw('tid, ip'))
//        ->groupBy(DB::raw('tid, ip'))
//        ->get();

//    $rs = DB::select('select a.tid, title, count(*) as person from (select tid, ip from votes group by tid, ip) as a inner join topics on a.tid = topics.tid group by tid order by person desc');
//
//    echo '<pre>';
//    print_r($rs);
});

Route::get('userinfo', function() {
    return view('userinfo');
});


